/**
 * 示例JSON Schema配置
 */

import { FIELD_TYPES, UI_TYPES, CONDITION_TYPES } from '@/types/schema.js'

// 基础表单示例
export const basicFormSchema = {
  type: FIELD_TYPES.OBJECT,
  title: '用户信息表单',
  description: '请填写完整的用户基本信息',
  properties: {
    name: {
      type: FIELD_TYPES.STRING,
      title: '姓名',
      description: '请输入您的真实姓名',
      minLength: 2,
      maxLength: 10,
      'x-ui': {
        type: UI_TYPES.INPUT,
        placeholder: '请输入姓名',
        clearable: true
      }
    },
    email: {
      type: FIELD_TYPES.STRING,
      title: '邮箱',
      format: 'email',
      'x-ui': {
        type: UI_TYPES.INPUT,
        placeholder: '请输入邮箱地址'
      }
    },
    age: {
      type: FIELD_TYPES.INTEGER,
      title: '年龄',
      minimum: 18,
      maximum: 65,
      'x-ui': {
        type: UI_TYPES.NUMBER_INPUT,
        min: 18,
        max: 65
      }
    },
    gender: {
      type: FIELD_TYPES.STRING,
      title: '性别',
      enum: ['male', 'female'],
      'x-ui': {
        type: UI_TYPES.RADIO,
        options: [
          { label: '男', value: 'male' },
          { label: '女', value: 'female' }
        ]
      }
    },
    bio: {
      type: FIELD_TYPES.STRING,
      title: '个人简介',
      maxLength: 200,
      'x-ui': {
        type: UI_TYPES.TEXTAREA,
        rows: 4,
        placeholder: '请简单介绍一下自己...',
        showWordLimit: true
      }
    }
  },
  required: ['name', 'email', 'age']
}

// 复杂表单示例（包含联动）
export const complexFormSchema = {
  type: FIELD_TYPES.OBJECT,
  title: '员工入职申请表',
  description: '请完整填写入职申请信息，带*号为必填项',
  properties: {
    personalInfo: {
      type: FIELD_TYPES.OBJECT,
      title: '个人信息',
      properties: {
        name: {
          type: FIELD_TYPES.STRING,
          title: '姓名',
          minLength: 2,
          maxLength: 20,
          'x-ui': {
            type: UI_TYPES.INPUT,
            placeholder: '请输入真实姓名'
          }
        },
        mobile: {
          type: FIELD_TYPES.STRING,
          title: '手机号',
          format: 'mobile',
          'x-ui': {
            type: UI_TYPES.INPUT,
            placeholder: '请输入11位手机号'
          }
        },
        email: {
          type: FIELD_TYPES.STRING,
          title: '邮箱',
          format: 'email',
          'x-ui': {
            type: UI_TYPES.INPUT,
            placeholder: '请输入邮箱地址'
          }
        },
        idCard: {
          type: FIELD_TYPES.STRING,
          title: '身份证号',
          format: 'idcard',
          'x-ui': {
            type: UI_TYPES.INPUT,
            placeholder: '请输入18位身份证号'
          }
        }
      }
    },
    jobInfo: {
      type: FIELD_TYPES.OBJECT,
      title: '职位信息',
      properties: {
        department: {
          type: FIELD_TYPES.STRING,
          title: '部门',
          enum: ['tech', 'product', 'marketing', 'hr', 'finance'],
          'x-ui': {
            type: UI_TYPES.SELECT,
            placeholder: '请选择部门',
            options: [
              { label: '技术部', value: 'tech' },
              { label: '产品部', value: 'product' },
              { label: '市场部', value: 'marketing' },
              { label: '人事部', value: 'hr' },
              { label: '财务部', value: 'finance' }
            ]
          }
        },
        position: {
          type: FIELD_TYPES.STRING,
          title: '职位',
          'x-ui': {
            type: UI_TYPES.SELECT,
            placeholder: '请选择职位',
            options: []
          },
          'x-conditions': [
            {
              when: {
                field: 'jobInfo.department',
                operator: CONDITION_TYPES.EQUALS,
                value: 'tech'
              },
              then: {
                type: 'setOptions',
                value: [
                  { label: '前端工程师', value: 'frontend' },
                  { label: '后端工程师', value: 'backend' },
                  { label: '全栈工程师', value: 'fullstack' },
                  { label: '测试工程师', value: 'qa' },
                  { label: '运维工程师', value: 'devops' }
                ]
              }
            },
            {
              when: {
                field: 'jobInfo.department',
                operator: CONDITION_TYPES.EQUALS,
                value: 'product'
              },
              then: {
                type: 'setOptions',
                value: [
                  { label: '产品经理', value: 'pm' },
                  { label: '产品设计师', value: 'designer' },
                  { label: '用户研究员', value: 'ux' }
                ]
              }
            },
            {
              when: {
                field: 'jobInfo.department',
                operator: CONDITION_TYPES.EQUALS,
                value: 'marketing'
              },
              then: {
                type: 'setOptions',
                value: [
                  { label: '市场专员', value: 'marketing_specialist' },
                  { label: '品牌经理', value: 'brand_manager' },
                  { label: '运营专员', value: 'operation_specialist' }
                ]
              }
            }
          ]
        },
        expectedSalary: {
          type: FIELD_TYPES.NUMBER,
          title: '期望薪资',
          minimum: 3000,
          maximum: 50000,
          'x-ui': {
            type: UI_TYPES.NUMBER_INPUT,
            min: 3000,
            max: 50000,
            step: 500,
            placeholder: '请输入期望薪资'
          }
        },
        startDate: {
          type: FIELD_TYPES.STRING,
          title: '期望入职日期',
          format: 'date',
          'x-ui': {
            type: UI_TYPES.DATE_PICKER,
            placeholder: '请选择入职日期',
            shortcuts: [
              {
                text: '明天',
                value: new Date(Date.now() + 24 * 60 * 60 * 1000)
              },
              {
                text: '一周后',
                value: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000)
              },
              {
                text: '一个月后',
                value: new Date(Date.now() + 30 * 24 * 60 * 60 * 1000)
              }
            ]
          }
        }
      }
    },
    experience: {
      type: FIELD_TYPES.OBJECT,
      title: '工作经验',
      properties: {
        hasExperience: {
          type: FIELD_TYPES.BOOLEAN,
          title: '是否有相关工作经验',
          default: false,
          'x-ui': {
            type: UI_TYPES.SWITCH,
            activeText: '有',
            inactiveText: '无'
          }
        },
        years: {
          type: FIELD_TYPES.NUMBER,
          title: '工作年限',
          minimum: 0,
          maximum: 20,
          'x-ui': {
            type: UI_TYPES.SLIDER,
            min: 0,
            max: 20,
            step: 0.5,
            showStops: true
          },
          'x-conditions': [
            {
              when: {
                field: 'experience.hasExperience',
                operator: CONDITION_TYPES.EQUALS,
                value: false
              },
              then: {
                type: 'hide'
              }
            },
            {
              when: {
                field: 'experience.hasExperience',
                operator: CONDITION_TYPES.EQUALS,
                value: true
              },
              then: {
                type: 'show'
              }
            }
          ]
        },
        description: {
          type: FIELD_TYPES.STRING,
          title: '工作经历描述',
          maxLength: 500,
          'x-ui': {
            type: UI_TYPES.TEXTAREA,
            rows: 4,
            placeholder: '请详细描述您的工作经历...',
            showWordLimit: true
          },
          'x-conditions': [
            {
              when: {
                field: 'experience.hasExperience',
                operator: CONDITION_TYPES.EQUALS,
                value: false
              },
              then: {
                type: 'hide'
              }
            }
          ]
        }
      }
    },
    skills: {
      type: FIELD_TYPES.ARRAY,
      title: '技能标签',
      items: {
        type: FIELD_TYPES.STRING
      },
      'x-ui': {
        type: UI_TYPES.CHECKBOX,
        options: [
          { label: 'JavaScript', value: 'javascript' },
          { label: 'Vue.js', value: 'vue' },
          { label: 'React', value: 'react' },
          { label: 'Node.js', value: 'nodejs' },
          { label: 'Python', value: 'python' },
          { label: 'Java', value: 'java' },
          { label: 'Go', value: 'go' },
          { label: 'Docker', value: 'docker' },
          { label: 'Kubernetes', value: 'k8s' }
        ]
      }
    },
    rating: {
      type: FIELD_TYPES.NUMBER,
      title: '自我评价',
      minimum: 1,
      maximum: 5,
      'x-ui': {
        type: UI_TYPES.RATE,
        max: 5,
        showText: true,
        texts: ['很差', '较差', '一般', '良好', '优秀']
      }
    },
    agreement: {
      type: FIELD_TYPES.BOOLEAN,
      title: '我已阅读并同意',
      'x-ui': {
        type: UI_TYPES.CHECKBOX,
        options: [
          { label: '《入职协议》和《隐私政策》', value: true }
        ]
      }
    }
  },
  required: [
    'personalInfo.name',
    'personalInfo.mobile',
    'personalInfo.email',
    'jobInfo.department',
    'jobInfo.position',
    'agreement'
  ]
}

// 动态表单示例
export const dynamicFormSchema = {
  type: FIELD_TYPES.OBJECT,
  title: '产品订购表单',
  description: '根据不同产品类型显示不同的配置选项',
  properties: {
    productType: {
      type: FIELD_TYPES.STRING,
      title: '产品类型',
      enum: ['laptop', 'phone', 'tablet'],
      'x-ui': {
        type: UI_TYPES.RADIO,
        button: true,
        options: [
          { label: '笔记本电脑', value: 'laptop' },
          { label: '智能手机', value: 'phone' },
          { label: '平板电脑', value: 'tablet' }
        ]
      }
    },
    brand: {
      type: FIELD_TYPES.STRING,
      title: '品牌',
      'x-ui': {
        type: UI_TYPES.SELECT,
        placeholder: '请选择品牌',
        options: []
      },
      'x-conditions': [
        {
          when: {
            field: 'productType',
            operator: CONDITION_TYPES.EQUALS,
            value: 'laptop'
          },
          then: {
            type: 'setOptions',
            value: [
              { label: '苹果', value: 'apple' },
              { label: '联想', value: 'lenovo' },
              { label: '戴尔', value: 'dell' },
              { label: '华为', value: 'huawei' }
            ]
          }
        },
        {
          when: {
            field: 'productType',
            operator: CONDITION_TYPES.EQUALS,
            value: 'phone'
          },
          then: {
            type: 'setOptions',
            value: [
              { label: '苹果', value: 'apple' },
              { label: '华为', value: 'huawei' },
              { label: '小米', value: 'xiaomi' },
              { label: '三星', value: 'samsung' }
            ]
          }
        },
        {
          when: {
            field: 'productType',
            operator: CONDITION_TYPES.EQUALS,
            value: 'tablet'
          },
          then: {
            type: 'setOptions',
            value: [
              { label: '苹果', value: 'apple' },
              { label: '华为', value: 'huawei' },
              { label: '三星', value: 'samsung' }
            ]
          }
        }
      ]
    },
    price: {
      type: FIELD_TYPES.NUMBER,
      title: '价格',
      'x-ui': {
        type: UI_TYPES.INPUT,
        readonly: true,
        placeholder: '价格将根据配置自动计算'
      },
      'x-conditions': [
        {
          when: {
            operator: 'and',
            conditions: [
              { field: 'productType', operator: CONDITION_TYPES.EQUALS, value: 'laptop' },
              { field: 'brand', operator: CONDITION_TYPES.EQUALS, value: 'apple' }
            ]
          },
          then: {
            type: 'calculate',
            value: '10000 + (storage === "512gb" ? 2000 : storage === "1tb" ? 4000 : 0)'
          }
        }
      ]
    },
    storage: {
      type: FIELD_TYPES.STRING,
      title: '存储容量',
      'x-ui': {
        type: UI_TYPES.SELECT,
        placeholder: '请选择存储容量'
      },
      'x-conditions': [
        {
          when: {
            field: 'productType',
            operator: CONDITION_TYPES.IN,
            value: ['laptop', 'tablet']
          },
          then: {
            type: 'setOptions',
            value: [
              { label: '256GB', value: '256gb' },
              { label: '512GB', value: '512gb' },
              { label: '1TB', value: '1tb' }
            ]
          }
        },
        {
          when: {
            field: 'productType',
            operator: CONDITION_TYPES.EQUALS,
            value: 'phone'
          },
          then: {
            type: 'setOptions',
            value: [
              { label: '128GB', value: '128gb' },
              { label: '256GB', value: '256gb' },
              { label: '512GB', value: '512gb' }
            ]
          }
        }
      ]
    },
    color: {
      type: FIELD_TYPES.STRING,
      title: '颜色',
      'x-ui': {
        type: UI_TYPES.RADIO,
        options: [
          { label: '深空灰', value: 'space_gray' },
          { label: '银色', value: 'silver' },
          { label: '金色', value: 'gold' }
        ]
      }
    },
    quantity: {
      type: FIELD_TYPES.INTEGER,
      title: '购买数量',
      minimum: 1,
      maximum: 10,
      default: 1,
      'x-ui': {
        type: UI_TYPES.NUMBER_INPUT,
        min: 1,
        max: 10
      }
    },
    urgency: {
      type: FIELD_TYPES.BOOLEAN,
      title: '加急配送',
      default: false,
      'x-ui': {
        type: UI_TYPES.SWITCH,
        activeText: '是',
        inactiveText: '否'
      }
    },
    shippingAddress: {
      type: FIELD_TYPES.STRING,
      title: '配送地址',
      'x-ui': {
        type: UI_TYPES.TEXTAREA,
        rows: 3,
        placeholder: '请输入详细的配送地址'
      },
      'x-conditions': [
        {
          when: {
            field: 'urgency',
            operator: CONDITION_TYPES.EQUALS,
            value: true
          },
          then: {
            type: 'setRequired',
            value: true
          }
        }
      ]
    }
  },
  required: ['productType', 'brand', 'storage', 'color', 'quantity']
}

export default {
  basicFormSchema,
  complexFormSchema,
  dynamicFormSchema
}